<template>
  <div class="icons">
    <div class="swiper">
      <swiper :options="swiperOption">
        <swiper-slide v-for="(page, index) of pages" :key="index">
            <div class="icon" v-for="item of page" :key="item.id">
              <div class="icon-img-box">
                <img class="icon-img" :src="item.imgUrl" />
              </div>
              <p class="icon-title">{{item.desc}}</p>
            </div>
        </swiper-slide>
        <div class="swiper-pagination"  slot="pagination"></div>
      </swiper>
    </div>
  </div>
</template>

<script type="text/ecmascript-6">
export default {
  name: 'IconMenu',
  props: {
    iconList: Array
  },
  data () {
    return {
      swiperOption: {
        pagination: '.swiper-pagination'
      }
    }
  },
  computed: {
    pages () {
      const pages = []
      this.iconList.forEach(function (item, index) {
        const page = Math.floor(index / 8)
        if (!pages[page]) {
          pages[page] = []
        }
        pages[page].push(item)
      })
      return pages
    }
  }
}
</script>

<style lang="scss" scoped>
  @import "~styles/scss/variable.scss";
  @import "~styles/scss/mixins.scss";
  .icons {
    font-size: 0;
    background: #fff;
    @include fixedHeght(50%);
    .icon {
      position: relative;
      float: left;
      width: 25%;
      padding-bottom: 22%;
      font-size: $fontSize-regular;
      text-align: center;
      &-img-box {
        position: absolute;
        top: .3rem;
        right: .3rem;
        bottom: .44rem;
        left: .3rem;
        img {
          height: 100%;
        }
      }
      &-title {
        position: absolute;
        bottom: 0;
        left: 0;
        right: 0;
        text-align: center;
        @include ellipsis();
      }
    }
  }
  .swiper-slide {
    overflow: hidden;
    height: 0;
    padding-bottom: 50%;
  }
  .swiper-pagination {
    bottom: .1rem;
  }
</style>
